﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BAL;
using Channelvn.Cached.Common;
using System.Configuration;

namespace ProjectQuaDep.Ajax
{
    public partial class Ajax_BoxDoatGiai : System.Web.UI.Page
    {
        private int Top_Slide = 5;
        private int Top_Cont = 4;
        private int Width_Slide = 321;
        private int Height_Slide = 202;
        private int Width_Cont = 157;
        private int Height_Cont = 98;
        private string ImagesIds = string.Empty,url = string.Empty;
        private int CurrentRound = 0;
        private int awardId = 0, pageType = 0;
        private int pageIndex = 0, pageSize = 5, pageIndex_Cont = 0, pageSize_Cont = 4; 

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                awardId = Lib.QueryString.AwardsID;
                pageIndex = Lib.QueryString.PageIndex;
                pageType = Lib.QueryString.PageType;
                CurrentRound = Lib.QueryString.RoundAwards;
                if (CurrentRound == 0)
                    CurrentRound = Utils.GetCurrentRound();
                DataTable dt = BussinessHelpers.BoxDatGiai(Top_Slide, 0, 0, Width_Slide, Height_Slide, pageIndex, pageSize, pageType);
                if (Utils.TableIsNotNullOrEmpty(dt))
                {
                    rptData.DataSource = dt;
                    rptData.DataBind();

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        ImagesIds += dr[Const.Images.ImageId].ToString() + ",";
                    }
                }

                dt = BussinessHelpers.BoxDatGiai_Cont(Top_Cont, 0, 0, ImagesIds, Width_Cont, Height_Cont, pageIndex, pageSize_Cont, pageType);
                if (Utils.TableIsNotNullOrEmpty(dt))
                {
                    rptData_Cont.DataSource = dt;
                    rptData_Cont.DataBind();
                }
            }
        }

        protected void rptData_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal ltrBinhChon = (Literal)e.Item.FindControl("ltrBinhChon");

                int ImageId = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row[Const.Images.ImageId].ToString());
                int LikeWeb = 0;
                if (!string.IsNullOrEmpty(((DataRowView)e.Item.DataItem).Row[Const.Images.LikeWeb].ToString()))
                    LikeWeb = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row[Const.Images.LikeWeb].ToString());
                string Url = ((DataRowView)e.Item.DataItem).Row[Const.Images.Url].ToString();
                if (LikeWeb > 0)
                    ltrBinhChon.Text = LikeWeb.ToString();
                //ltrScritp.Text += "<script type=\"text/javascript\">getFacebookCommentCount('" + ConfigurationManager.AppSettings["Domain"] + Url + "', function (count) {if(count> 0)  $('.countdgfb_" + ImageId + " div.innertext').html(count + ' bình luận'); });</script>";
                string strQuery = "https://graph.facebook.com/fql?q=SELECT%20url,%20normalized_url,%20share_count,%20like_count,%20comment_count,%20total_count,commentsbox_count,%20comments_fbid,%20click_count%20FROM%20link_stat%20WHERE%20url=%27" + ConfigurationManager.AppSettings["Domain"] + Url + "%27";
                ltrScritp.Text += "<script type=\"text/javascript\">getFacebookCommentCount('" + strQuery + "', function (share,comment) {if(share> 0)  $('.countsharedgfb_" + ImageId + " div.innertext').html(share); if(comment> 0)  $('.countdgfb_" + ImageId + " div.innertext').html(comment); });</script>";
            }
        }

        protected void rptData_Cont_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
            }
        }
    }
}